package com.example.todolist.util;

import com.qiniu.storage.Region;
import com.qiniu.util.Auth;
import com.qiniu.util.StringMap;

/**
 * @author: yoonada
 * @email: m15602498163@163.com
 * @create: 2021-12-10 00:24
 * @description: 七牛云对象存储工具类
 */

public class QiniuKodoUtil {


    /**
     * 生成上传token
     * @param dto
     * @return
     */
    public static String generateUploadToken(QiniuKodoDTO dto){
        Auth auth = Auth.create(dto.getAccessKey(), dto.getSecretKey());
        StringMap policy = new StringMap();
        policy.put("callbackBody", "{\"key\":\"$(key)\",\"hash\":\"$(etag)\",\"bucket\":\"$(bucket)\",\"fsize\":$(fsize)}");
        policy.put("callbackBodyType", "application/json");
        return auth.uploadToken(dto.getBucket(), null, 3600, policy);
    }


    public static Region regionHd() {
        return new Region.Builder()
                .srcUpHost("upload-z2.qiniup.com")
                .accUpHost("upload-z2.qiniup.com")
                .iovipHost("iovip-z0.qbox.me")
                .rsHost("rs-z0.qbox.me")
                .rsfHost("rsf-z0.qbox.me")
                .apiHost("api-z0.qiniu.com")
                .build();
    }

}